public class test {
	// 调整数组顺序使得奇数在偶数之前，调整之后，不关心大小顺序。
	public static void func(int[] arr) {
		if (arr == null || arr.length <= 1) {
			return; // 处理空数组或只有一个元素的情况
		}

		int left = 0;
		int right = arr.length - 1;

		while (left < right) {
			// 左指针从左往右找第一个偶数
			while (left < right && arr[left] % 2 != 0) {
				left++;
			}

			// 右指针从右往左找第一个奇数
			while (left < right && arr[right] % 2 == 0) {
				right--;
			}

			// 交换左右指针所指元素
			if (left < right) {
				int temp = arr[left];
				arr[left] = arr[right];
				arr[right] = temp;
			}
		}
	}

	public static void main(String[] args) {
		int[] arr = new int[]{1, 2, 3, 4, 5};
		int[] arr2 = new int[]{1, 3, 5, 7, 9};
		int[] arr3 = new int[]{2, 4, 6, 8, 10};

		func(arr);
		System.out.print("arr: ");
		for (int i = 0; i < arr.length; i++) {
			System.out.print(arr[i] + " ");
		}
		System.out.println();

		func(arr2);
		System.out.print("arr2: ");
		for (int i = 0; i < arr2.length; i++) {
			System.out.print(arr2[i] + " ");
		}
		System.out.println();

		func(arr3);
		System.out.print("arr3: ");
		for (int i = 0; i < arr3.length; i++) {
			System.out.print(arr3[i] + " ");
		}
	}
}
